package com.xxmw.transaction.enumeration;

import com.xxmw.transaction.common.excep.service.TransactionException;
import com.xxmw.transaction.common.utils.symbolFormat.SymbolFormat;
import com.xxmw.transaction.common.utils.symbolFormat.impl.*;

/**
 * 交易所枚举
 * @author luowenliang
 * @since 2020/2/25 17:44
 */
public enum BourseEnum {

    HUOBI(1, "火币", new HuobiSymbolFormat()),
    BINANCE(2, "币安",new BinanceSymbolFormat()),
    OKEX(3, "okex", new OkexSymbolFormat()),
    BITFOREX(4, "币夫", new BitforexSymbolFormat()),
    ZB(5, "ZB", new ZbsymbolFormat()),
    POLONIEX(6, "poloniex", new PoloniexSymbolFormat()),
    JIUBI(7, "久币网", null),
    BIKI(8, "BiKi", null);

    private int value;

    private String desc;

    private SymbolFormat symbolFormat;

    BourseEnum(int value, String desc, SymbolFormat symbolFormat) {
        this.value = value;
        this.desc = desc;
        this.symbolFormat = symbolFormat;
    }

    public int getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public SymbolFormat getSymbolFormat(){
      return this.symbolFormat;
    };

    public static SymbolFormat getFormatByBourse(int bourse) {
        BourseEnum[] enums = BourseEnum.values();
        for (BourseEnum formatEnum : enums) {
            if (formatEnum.value == bourse) {
                return formatEnum.symbolFormat;
            }
        }
        throw new TransactionException("未找到对应交易所的交易对配置");
    }

    public static String getDescByValue (int value) {
        for (BourseEnum bourseEnum : BourseEnum.values()) {
            if (bourseEnum.getValue() == value) {
                return bourseEnum.getDesc();
            }
        }
        return null;
    }
}
